// pages/logistics/logistics.js
const app = getApp()
var url = require('../../utils/url.js')
var token;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    express: "",
    expressCode:"",
    refundId:""
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var id=options.id;
    this.setData({
      refundId:id
    })
    wx.getStorage({
      key: 'token',
      success: function(res) {
        token=res.data
      },
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },
  express:function(e){
    this.setData({
      express:e.detail.value
    })
  },
  expressCode: function (e) {
    this.setData({
      expressCode: e.detail.value
    })
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },
  save:function(){
    var that=this;
    var expressCode = that.data.expressCode;
    var express = that.data.express;
    var refundId = that.data.refundId;
    if (express.length==0){
       wx.showToast({
         title: '请填写物流公司',
         icon: 'none',
       })
    } else if (expressCode.length == 0){
      wx.showToast({
        title: '请填写快递单号',
        icon: 'none',
      })
    }else{
      wx.request({
        url: url.URl + 'my/order/refund/express',
        data: { refund_id: refundId, express: express, express_code: expressCode},
        method: 'post',
        header: {
          'Authorization': token
        },
        success: function (res) {
          console.log(res)
          var msg = res.data.msg;
          if (res.data.code == 200) {
            wx.navigateTo({
              url: '/pages/success/success',
              success: function (res) { },
              fail: function (res) { },
              complete: function (res) { },
            })
          } else {
            wx.showToast({
              title: msg,
              icon: 'none',
              duration: 2000
            })
          }
        }
      })
    }
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})